#include"process.h"
#include<unistd.h>
#include<string.h>
#include<stdio.h>
#define NUM 101
#define STYLE '#'

void FlushProcess(double total,double current)
{
    char buffer[NUM];
    memset(buffer,0,sizeof(buffer));
    const char* lable = "|/-\\";
    int len = strlen(lable);

    int num = (int)current/total*100;//进度取整，更新进度条
    
    for(int i = 0;i < num ;i++)
    {
        buffer[i] = STYLE;
    }
    double rate = current/total*100;//进度，以百分比形式呈现
    static int count = 0;//下载的情况和total，current都无关，与函数调用的情况有关
                         //static修饰的变量只会初始化一次
    printf("[%-100s][%.1lf%%][%c]\r",buffer,rate,lable[count % len]);
    count++;
    fflush(stdout);


}

void process_v1()
{
    char buffer[NUM];
    memset(buffer,0,sizeof(buffer));
    const char* lable = "|/-\\";
    int len = strlen(lable);
    int count = 0;

    while(count <= 100)
    {
        printf("[%-100s][%d%%][%c]\r",buffer,count,lable[count % len]);
        fflush(stdout);
        buffer[count] = STYLE;
        count++;
        usleep(50000);
    }
    printf("\n");
}
